package com.igeek.singleton;

/**
 * 单例模式：
 *      懒汉模式
 */
public class Lazy {

    //1.私有化构造函数
    private Lazy(){}

    //2.创建全局变量
    private static Lazy lazy = null;

    //3.提供方法返回对象
    public static Lazy getInstance(){

        if(lazy == null){
            lazy = new Lazy();
        }
        return lazy;
    }
}

class LazyTest{

    public static void main(String[] args) {
        Lazy lazy = Lazy.getInstance();
        Lazy lazy1 = Lazy.getInstance();

        System.out.println(lazy.hashCode() + "===" + lazy1.hashCode());
    }
}
